
    ; (function () {

        $(function () {
            $("#header").load("./header.html")
            $("#footer").load("./footer.html")

            $(".buttons").children("button").on("mouseenter", function () {
                $(this).css("background", "#5643ec")
            })
            $(".buttons").children("button").on("mouseleave", function () {
                $(this).css("background", "#d0d0d0")
            })

            $(".form2").children().eq(3).children().on("click", function () {
                window.location = "./reg.html"
            })


            $("form").validate({
                rules: {
                    uphone: {
                        required: true
                    },
                    upwd: {
                        required: true
                    }
                },
                messages: {
                    uphone: "请输入账号!",
                    upwd: "请输入密码!"
                },
                submitHandler() {
                    // var userList = JSON.parse($.cookie("users") || '[]');
                    // var obj = {
                    //     uname: $("[name='uname']").val(),
                    //     upwd: $("[name='upwd']").val()
                    // }
                    // var flag = userList.some((el) => {
                    //     return ((el.uemail == obj.uname) || (el.uphone == obj.uname)) && el.upwd == obj.upwd
                    // })
                    console.log($("form").serialize())
                    $.ajax({
                        url: "./api/login",
                        type: "post",
                        data: $("form").serialize(),
                    }).done(function (res) {
                        if (res.status == 1) {
                            console.log(res.data)
                            console.log(JSON.stringify(res.data))
                            //把当前登录成功的用户id,用户名等保存到localStorage
                            localStorage.setItem("users", JSON.stringify(res.data));
                            layer.confirm("登录成功!", {
                                btn: ["确定", "取消"]
                            }, (index) => {
                                layer.close(index);
                                setTimeout(() => {
                                    location = "./index.html"
                                }, 1500)
                            }, (index) => {
                                layer.close(index);
                            })

                        } else {
                            layer.msg(res.msg);
                        }
                    })

                    // if (flag) {
                    //     layer.alert("登录成功")
                    //     setTimeout(function () {
                    //         window.location = "index.html"
                    //     }, 1500)

                    // } else {
                    //     layer.msg("用户名或密码错误")
                    // }

                    return false;
                }
            })

        })
    })()